#ifndef NET_INFO_H_INCLUDED
#define NET_INFO_H_INCLUDED

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <string.h>
#include <dirent.h>

#include "../cjson/cJSON.h"

#define  TCP_MAX_LEN 4096

typedef struct {
    char local_ip[17];
    char local_port[6];
    char remote_ip[17];
    char remote_port[6];
    char st[3];                             /*套接字状态
											TCP_ESTABLISHED:1   TCP_SYN_SENT:2
											TCP_SYN_RECV:3      TCP_FIN_WAIT1:4
											TCP_FIN_WAIT2:5     TCP_TIME_WAIT:6
											TCP_CLOSE:7         TCP_CLOSE_WAIT:8
											TCP_LAST_ACL:9      TCP_LISTEN:10
											TCP_CLOSING:11*/


    char transmit_queue[17];				//发送队列中数据长度
    char receive_queue[17];				    /*根据状态不同有不同表示
											receive-queue，当状态是ESTABLISHED，表示接收队列中数据长度；状态是LISTEN，
											表示已经完成连接队列的长度。*/
    char tcp_timer[2];				    /*当状态是ESTABLISHED，表示接收队列中数据长度；状态是LISTEN，表示已经完成连接队列的长度。
											  0  no timer is pending  //没有启动定时器
											  1  retransmit-timer is pending  //重传定时器
											  2  another timer (e.g. delayed ack or keepalive) is pending  //连接定时器、FIN_WAIT_2定时器或TCP保活定时器
											  3  this is a socket in TIME_WAIT state. Not all fields will contain data (or even exist)  //TIME_WAIT定时器
											  4  zero window probe timer is pending  //持续定时器*/
    char timer_expires[8];					 //超时时间，单位是jiffies
    char timeout_resend_times[8];			//超时重传次数
    char uid[10];
    char timeout[5];						//持续定时器或保活定时器周期性发送出去但未被确认的TCP段数目，在收到ACK之后清零
    char inode[15];							//套接字对应的inode
    char socket_times[10];					//socket结构体的引用数
    char socket_mem_addr[32];				//socket 内存地址
    char RTO[8];
    char delay[8];
    char quick_flag[8];
    char win_size[8];
    char threshold[8];
}Tcp_detail;



void get_net_rate(long* rev,long* send);
cJSON *  get_net_connections(long* conn_count);
Tcp_detail* get_net_connections_infos(long* conn_count);

#endif // NET_INFO_H_INCLUDED
